<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    img {
      width: 300px;
      height: 300px;

    }
  </style>
</head>
<body>
  <button>切换</button><br>
  
  <img src="./images/1.jpg" alt="">
  
</body>
<script>
  const btn = document.querySelector('button');
  const img= document.querySelector('img');
 
  btn.addEventListener('click',function(){
    let index=Math.floor(Math.random()*3+1)
    img.src=`./images/${index}.jpg`

  })
</script>

</html>